<template>
  <div class="server-main">
    <el-form :inline="true" v-model="modelData" class="search-form">
      <el-form-item class="form-input">
        <el-input
          type="textarea"
          :disabled="recommendId ? true : false"
          :autosize="{ minRows: 3, maxRows: 10 }"
          placeholder="这里是输入的需求"
          v-model.trim="modelData.item_description"
        ></el-input>
      </el-form-item>
    </el-form>

    <div class="server-table">
      <div class="table-title">
        <span class="table-title-text"></span>
        <div>
          <el-button
            type="primary"
            size="small"
            :disabled="recommendId ? true : false"
            @click="openCreateProperty"
            >用例及工具推荐</el-button
          >
        </div>
      </div>
      <el-table :data="tableList1" class="tableClass km-table" height="300">
        <el-table-column
          prop="objectName"
          label="测试用例名称"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="caseFlag"
          label="用例标识"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="rounds"
          label="轮次"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="testDescription"
          label="测试说明"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="presetCondition"
          label="预置条件"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="method"
          label="menthod"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="inputOperation"
          label="输入及操作说明"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <!-- <el-table-column prop="prop7" label="期望测试结果" align="center"></el-table-column> -->
        <el-table-column
          prop="endCondition"
          label="终止条件"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="passRule"
          label="通过准则"
          align="center"
        ></el-table-column>
      </el-table>
      <el-table :data="tableList2" class="tableClass km-table">
        <el-table-column
          type="index"
          label="编号"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="key"
          label="测试工具名称"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="value"
          label="测试工具版本"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
      <el-table :data="tableList3" class="tableClass km-table">
        <el-table-column
          type="index"
          label="编号"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="key"
          label="陪测软件名称"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="value"
          label="软件版本"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
      <el-table :data="tableList4" class="tableClass km-table">
        <el-table-column
          type="index"
          label="编号"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="key"
          label="陪测硬件"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="value"
          label="品牌"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { mapState, mapMutations } from "vuex";
export default {
  name: "intelligenceRec",
  components: {},
  data: () => {
    return {
      recommendId: null,
      modelData: {
        item_description: "", // 输入端需求
        pageNum: 1, // 页码
        pageSize: 10, // 每页条数
      },
      tableList1: [], // 第一张表
      tableList2: [], // 第二张表
      tableList3: [], // 第三张表
      tableList4: [], // 第四张表
      // total: 0, // 数据总条数
    };
  },
  computed: {
    ...mapState({
      containerDom: (state) => state.server.containerDom,
    }),
  },
  mounted() {
    const { recommendId } = this.$route.query;
    if (recommendId) {
      this.recommendId = recommendId;
      this.getTableList();
    }
  },
  methods: {
    // 查询
    onSubmit(pageNum) {
      this.modelData.pageNum = pageNum ? pageNum : this.modelData.pageNum;
    },

    // 通过查看按钮获取表格数据
    async getTableList() {
      let params = {
        recommendId: this.recommendId,
      };
      let res = await this.$axios.post(
        this.$api.caseResultRec.zehaoObj.selectByRecommendId,
        params
      );
      let { data, message } = res.data;
      if (message === "操作成功") {
        this.tableList1 = data.iaYlRecommendDetailList;
        // this.tableList1.map(item => {
        //   if (item.inputOperation) {
        //     item.inputOperation = JSON.parse(item.inputOperation)["input_and_behavior"]
        //   }
        //   return item;
        // });

        this.modelData.item_description = data.iaYlRecommend.requireContent;
        if (data.iaYlRecommend) {
          this.tableList2 = data.iaYlRecommend.toolss;
          this.tableList3 = data.iaYlRecommend.accompanySoftwares;
          this.tableList4 = data.iaYlRecommend.accompanyHardwares;
        } else {
          this.tableList2 = [];
          this.tableList3 = [];
          this.tableList4 = [];
        }

        return;
      } else {
        this.$message.warning(message);
      }
    },

    // 用例及工具推荐
    async openCreateProperty() {
      const { item_description } = this.modelData;
      let params = {
        item_description,
      };
      let res = await this.$axios.post(
        this.$api.caseResultRec.zehaoObj.intellectAlgorithm,
        params
      );
      let { message, data } = res.data;
      if (message === "操作成功") {
        this.tableList1 = data.iaYlRecommendDetailList;
        if (data.iaYlRecommend) {
          this.tableList2 = data.iaYlRecommend.toolss;
          this.tableList3 = data.iaYlRecommend.accompanySoftwares;
          this.tableList4 = data.iaYlRecommend.accompanyHardwares;
        } else {
          this.tableList2 = [];
          this.tableList3 = [];
          this.tableList4 = [];
        }
        return;
      } else {
        this.$message.warning(message);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.server-main {
  position: relative;

  .search-form {
    background: #ffffff;
    border-radius: 4px;
    padding: 16px 32px;
    .el-form-item {
      margin-bottom: 0;
    }

    .form-input {
      margin-right: 32px;
      .el-input,
      .el-select {
        ::v-deep .el-input__inner {
          width: 240px;
          height: 32px;
          background: #ffffff;
          border-radius: 2px;
          border: 1px solid #e0e0e0;
        }
      }
    }
  }

  .el-form {
    padding: 20px;

    .form-input {
      width: 100%;

      ::v-deep .el-form-item__content {
        width: 100%;
      }

      ::v-deep .el-textarea__inner {
        font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB,
          Microsoft YaHei, Arial, sans-serif;
      }
    }
  }

  .server-table {
    margin-top: 16px;
    padding: 16px 32px 64px;
    background: #ffffff;
    border-radius: 4px;

    .table-title {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .table-title-text {
        margin: 8px 0;
        font-size: 16px;
        line-height: 16px;
        border-left: 5px solid $--color-primary;
        padding-left: 10px;
      }

      margin-bottom: 10px;
    }
  }

  ::v-deep .el-table__append-wrapper {
    padding: 10px;
  }
}
</style>
